//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;
using System;

namespace OpenLS.Drawing
{
    public class Shape : ShapeBase, IShape
    {
        private bool _fLocksText;
        private bool _fPublished;
        private string _macro;
        private ShapeNonVisual _nvSpPr;
        private ShapeProperties _spPr;
        private ShapeStyle _style;
        private string _textlink;
        private TextBody _txBody;

        [Obsolete]
        public Geometry Geometry
        {
            get { return ShapeProperties.Geometry; }
        }

        internal ShapeNonVisual ShapeNonVisual
        {
            get { return _nvSpPr; }
            set { _nvSpPr = value; NotifyPropertyChanged("ShapeNonVisual"); }
        }

        public override ShapeProperties ShapeProperties
        {
            get { return _spPr; }
            set{ _spPr = value; NotifyPropertyChanged("ShapeProperties");}
        }

        public ShapeStyle Style
        {
            get { return _style; }
            set { _style = value; NotifyPropertyChanged("Style"); }
        }

        public TextBody TextProperties
        {
            get { return _txBody; }
            set { _txBody = value; NotifyPropertyChanged("TextProperties"); }
        }

        public string Macro
        {
            get { return _macro; }
            set { _macro = value; NotifyPropertyChanged("Macro"); }
        }

        public string TextLink
        {
            get { return _textlink; }
            set { _textlink = value; NotifyPropertyChanged("TextLink"); }
        }

        public bool LocksText
        {
            get { return _fLocksText; }
            set { _fLocksText = value; NotifyPropertyChanged("LocksText"); }
        }

        public bool Published
        {
            get { return _fPublished; }
            set { _fPublished = value; NotifyPropertyChanged("Published"); }
        }

        protected override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("sp")) //\\, OfficeConstants.SpreadsheetDrawingNamespaceUri))
            {
                _macro = c.GetOptionalString("macro");
                _textlink = c.GetOptionalString("textlink");
                _fLocksText = c.GetOptionalBoolean("fLocksText", false);
                _fPublished = c.GetOptionalBoolean("fPublished", false);
                ShapeNonVisual = c.ReadElement<ShapeNonVisual>();
                _spPr = c.ReadElement<ShapeProperties>();
                Style = c.ReadOptionalElement<ShapeStyle>("style");
                TextProperties = c.ReadOptionalElementAs<TextBody>("txBody");
            }
        }

        protected override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("sp"))
                //\\, "a", SpreadsheetConstants.SpreadsheetDrawingNamespaceUri))
            {
                c.SetOptionalString("macro", _macro);
                c.SetOptionalString("textlink", _textlink);
                c.SetOptionalBoolean("fLocksText", _fLocksText, false);
                c.SetOptionalBoolean("fPublished", _fPublished, false);
                c.WriteElement(ShapeNonVisual);
                c.WriteElement(ShapeProperties);
                c.WriteOptionalElement(Style);
                c.WriteOptionalElementAs(TextProperties, "txBody");
                //\\TextBody.WriteXmlAs("txBody", "a", SpreadsheetConstants.SpreadsheetDrawingNamespaceUri, c.Writer, c.Part);
            }
        }
    }
}